package com.umeox.watch.alphabetlearning.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.umeox.watch.alphabetlearning.R
import com.umeox.watch.alphabetlearning.bean.AlphabetBean

/**
 * Created by Rambo 2022/9/10
 * Describe:
 */
class ViewPagerAdapter(private val data: List<AlphabetBean>) : RecyclerView.Adapter<ViewPagerAdapter.ViewPagerHolder?>() {

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ViewPagerAdapter.ViewPagerHolder {
        return ViewPagerHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.item_pager, parent, false)
        )
    }

    override fun onBindViewHolder(holder: ViewPagerAdapter.ViewPagerHolder, position: Int) {
        holder.mImageView.setImageResource(data[position].resId)
        holder.mKeyTv.text = data[position].key
        holder.mWordTv.text = data[position].word
    }

    override fun getItemCount(): Int {
        return data.size
    }


    inner class ViewPagerHolder(itemView: View) :
        RecyclerView.ViewHolder(itemView) {
        var mImageView: ImageView
        var mKeyTv: TextView
        var mWordTv: TextView

        init {
            mImageView = itemView.findViewById(R.id.iv_alphabet_bg)
            mKeyTv = itemView.findViewById(R.id.tv_key)
            mWordTv = itemView.findViewById(R.id.tv_word)
        }
    }
}
